﻿using System.Linq;

using Styx;
using Styx.CommonBot;

using WuzzCollection.Helpers;

namespace WuzzCollection.Classes
{
    internal partial class Monk : AbstractClass
    {
        public void WindwalkerRotation()
        {
            float EnergyPerSec = 10;

            // On fleeing mobs
            if (Me.CurrentTarget.Fleeing && Me.CurrentTarget.Distance <= 40)
                if (Spell.CastSpell("Crackling Jade Lightning"))
                {
                    StyxWoW.SleepForLagDuration();
                    return;
                }

            if (!Me.CurrentTarget.IsPlayer && !Me.Auras.ContainsKey("Touch of Karma")
                    && Me.CurrentTarget.CurrentHealth <= Me.MaxHealth && Me.CurrentTarget.CurrentHealth >= (Me.MaxHealth * 0.5)
                    && Me.CurrentTarget.IsWithinMeleeRange)
                if (Spell.CastSpell("Touch of Death"))
                    return;

            if (Me.CurrentChi == 0 && Me.CurrentTarget.IsWithinMeleeRange)
                if (Spell.CastSpecial("Chi Brew"))
                    return;

            if ((!Unit.HasMyAura(Me.CurrentTarget, "Rising Sun Kick") || (Me.CurrentTarget.HasAura("Rising Sun Kick") && Me.CurrentTarget.Auras["Rising Sun Kick"].TimeLeft.TotalSeconds <= 3))
                && Me.CurrentTarget.IsWithinMeleeRange)
                if (Spell.CastSpell("Rising Sun Kick"))
                    return;

            if ((!Unit.HasMyAura(Me, "Tiger Power") || Me.Auras["Tiger Power"].TimeLeft.Seconds < 3) && Me.CurrentTarget.IsWithinMeleeRange)
                if (Spell.CastSpell("Tiger Palm"))
                    return;

            if (Unit.HasMyAura(Me, "Tigereye Brew", 10) && Me.CurrentTarget.IsWithinMeleeRange)
                if (Spell.CastBuff("Tigereye Brew"))
                    return;

            if (Me.CurrentEnergy <= (Me.MaxEnergy - (EnergyPerSec * 5)))
                if (Spell.CastBuff("Energizing Brew"))
                    return;

            if (BotSettings.BotCooldowns && Me.CurrentTarget.IsWithinMeleeRange)
                if (Spell.CastSpecial("Invoke Xuen, the White Tiger"))
                    return;

            if (StyxWoW.Me.CurrentTarget.IsWithinMeleeRange)
                if (Spell.CastSpell("Rushing Jade Wind"))
                    return;

            // AoE Rotation
            if (BotSettings.BotAOE && SpellManager.HasSpell("Spinning Crane Kick") && Unit.NearbyUnfriendlyUnits(8).Count() >= 5)
            {
                if (Me.CurrentChi == 4 && Me.CurrentTarget.IsWithinMeleeRange)
                    if (Spell.CastSpell("Rising Sun Kick"))
                        return;

                if (Spell.CastSpell("Spinning Crane Kick"))
                    return;
            }

            // Single Target Rotation
            else
            {
                if (Me.CurrentTarget.IsWithinMeleeRange)
                    if (Spell.CastSpell("Rising Sun Kick"))
                        return;

                if (!Me.HasAura("Energizing Brew") && Me.CurrentEnergy <= Me.MaxEnergy - (EnergyPerSec * 4) && Helpers.Unit.HasMyAura(Me, "Tiger Power") && Me.CurrentTarget.IsWithinMeleeRange)
                    if (Spell.CastSpell("Fists of Fury"))
                        return;

                if (Me.HasAura("Combo Breaker: Blackout Kick") && Me.CurrentTarget.IsWithinMeleeRange)
                    if (Spell.CastSpell("Blackout Kick"))
                        return;

                if (Me.CurrentChi >= 3 && Me.CurrentEnergy <= Me.MaxEnergy - (EnergyPerSec * 2) && Me.CurrentTarget.IsWithinMeleeRange)
                    if (Spell.CastSpell("Blackout Kick"))
                        return;

                //actions.st+=/tiger_palm,if=(buff.combo_breaker_tp.react&energy.time_to_max>=2)|(buff.combo_breaker_tp.remains<=2&buff.combo_breaker_tp.up)
                if (Me.HasAura("Combo Breaker: Tiger Palm") && Me.CurrentTarget.IsWithinMeleeRange)
                    if (Spell.CastSpell("Tiger Palm"))
                        return;

                if (Me.CurrentChi <= 2 && Me.CurrentTarget.IsWithinMeleeRange)
                    if (Spell.CastSpell("Jab"))
                        return;

                //actions.st+=/blackout_kick,if=((energy+(energy.regen*(cooldown.rising_sun_kick.remains)))>=40)|chi=4
                if (Me.CurrentChi == 4 && Me.CurrentTarget.IsWithinMeleeRange)
                    if (Spell.CastSpell("Blackout Kick"))
                        return;
            }
        }

    }
}
